const React = require('react')
const ReactDOMServer = require('react-dom/server')
const http = require('http')

//return <div>Hello</div>
function App(props) {
    return React.createElement('div', {}, props.children || 'Hello')
}


const server = http.createServer((req, res) => {
    res.end(`
            <!DOCTYPE html>
                <html lang="en">
                    <head>
                        <meta charset="UTF-8">
                        <title>My Application</title>
                    </head>
                    <body>
                        ${ReactDOMServer.renderToString(React.createElement(App, {}, 'this is my app'))}
                        <script>
                          // init react application...
                        </script>
                    </body>
                 </html>
    `)
})

/*设置监听的端口*/
const port = 3000;

server.listen(port, () => {
    console.log("listening on:", port)
})